﻿using System.ComponentModel.Composition;
using Monti.MVVM.Services;
using Peter.Common;

namespace Peter.Logic.Plugins
{
   /// <summary>
   /// Represents a plugin to view images.
   /// </summary>
   [Export (typeof (PeterPluginBase))]
   [PeterMetadata ("Image Viewer", "Jonathan Montiverdi", "A basic image viewer.", "0.1")]
   public class ImageViewerPlugin : PeterPluginBase, IFileOperations
   {
      /// <summary>
      /// Installs the plugin.
      /// </summary>
      public override void Install ()
      {
         var options = ServiceManager.Resolve <IPeterOptions> ();
         if (options != null)
         {
            options.RegisterToOpenExtension ("Image Viewer", ".png");
            options.RegisterToOpenExtension ("Image Viewer", ".bmp");
            options.RegisterToOpenExtension ("Image Viewer", ".jpg");
            options.RegisterToOpenExtension ("Image Viewer", ".ico");
            options.RegisterToOpenExtension ("Image Viewer", ".gif");
            options.RegisterToOpenExtension ("Image Viewer", ".jpeg");
         }
      }

      /// <summary>
      /// Opens the given file, return the dock content displaying the file.
      /// </summary>
      /// <param name="filePath">Full path to file to open.</param>
      /// <returns>Dock item displaying file.</returns>
      public void Open (string filePath)
      {
         var host = ServiceManager.Resolve<IPeterHost> ();
         host.AddDocument (new ImageViewModel (filePath));
      }

      /// <summary>
      /// Checks to see if the save command can/needs to be invoked.
      /// </summary>
      /// <returns>True if save can/needs to be invoked, otherswise false.</returns>
      public bool CanSave ()
      {
         return false;
      }

      /// <summary>
      /// Saves the current data.
      /// </summary>
      public void Save ()
      {
      }
   }
}
